import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { Configuration } from './configuration';
{{#useHttpClient}}import { HttpClient } from '@angular/common/http';{{/useHttpClient}}
{{^useHttpClient}}import { Http } from '@angular/http';{{/useHttpClient}}

{{#apiInfo}}
{{#apis}}
import { {{classname}} } from './{{importPath}}';
{{/apis}}
{{/apiInfo}}

@NgModule({
  imports:      [],
  declarations: [],
  exports:      [],
  providers: [{{^providedInRoot}}
    {{#apiInfo}}{{#apis}}{{classname}}{{#hasMore}},
    {{/hasMore}}{{/apis}}{{/apiInfo}} {{/providedInRoot}}]
})
export class {{apiModuleClassName}} {
    public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
        return {
            ngModule: {{apiModuleClassName}},
            providers: [ { provide: Configuration, useFactory: configurationFactory } ]
        };
    }

    constructor( @Optional() @SkipSelf() parentModule: {{apiModuleClassName}},
                 @Optional() http: {{#useHttpClient}}HttpClient{{/useHttpClient}}{{^useHttpClient}}Http{{/useHttpClient}}) {
        if (parentModule) {
            throw new Error('{{apiModuleClassName}} is already loaded. Import in your base AppModule only.');
        }
        if (!http) {
            throw new Error('You need to import the {{#useHttpClient}}HttpClientModule{{/useHttpClient}}{{^useHttpClient}}HttpModule{{/useHttpClient}} in your AppModule! \n' +
            'See also https://github.com/angular/angular/issues/20575');
        }
    }
}
